<template>
  <div class="moneySuccess-page">
    <h3>放款记录</h3>
    <AreaWarp :padding="true">
      <SearchWarp :label="'用户姓名'">
        <el-input v-model.trim="searchInfo.realname" placeholder="请输入用户姓名"></el-input>
      </SearchWarp>
      <SearchWarp :label="'手机号'">
        <el-input v-model.trim="searchInfo.mobile" maxlength="11" placeholder="请输入手机号码"></el-input>
      </SearchWarp>
      <SearchWarp :label="'打款金额'">
        <el-input class="inputWidth" v-model.trim="searchInfo.loanMoneyBegin" placeholder="起始金额"></el-input>-
        <el-input class="inputWidth" v-model.trim="searchInfo.loanMoneyEnd" placeholder="结束金额"></el-input>
      </SearchWarp>
      <SearchWarp :label="'打款时间'">
        <el-date-picker
          v-model="searchInfo.auditTime"
          type="daterange"
          :picker-options="pickerOptions"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :editable="false"
        ></el-date-picker>
      </SearchWarp>
      <BtnWarp>
        <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
        <el-button type="info" icon="el-icon-delete" @click="reset">重置</el-button>
      </BtnWarp>
    </AreaWarp>

    <AreaTitleWarp :title="'放款记录列表'">
      <el-button type="primary" @click="Refresh">刷新</el-button>
      <el-button type="primary" v-if="exportShow" @click="exportData">导出</el-button>
    </AreaTitleWarp>

    <!--搜索结果区域-->
    <AreaWarp :padding="false" v-loading="getLoaningListLoading">
      <el-table
        size="mini"
        :data="tableInfo.list"
        style="width: 100%"
        class="pub-table"
        header-row-class-name="pub-table-header-row"
        header-cell-class-name="pub-table-header-cell"
      >
        <el-table-column prop="borrowId" label="订单ID"></el-table-column>
        <el-table-column prop="realname" label="姓名"></el-table-column>
        <el-table-column prop="mobile" label="手机号" min-width="120"></el-table-column>
        <el-table-column prop="realCapital" label="打款金额" min-width="120"></el-table-column>
        <el-table-column prop="bankName" label="打款渠道-银行名称" min-width="150"></el-table-column>
        <el-table-column prop="cardNo" label="打款渠道-银行卡号" min-width="180"></el-table-column>
        <el-table-column
          prop="payTime"
          label="打款成功时间"
          min-width="180"
          :formatter="formatter_timeYMDHMS"
        ></el-table-column>
      </el-table>
      <el-pagination
        layout="total,sizes,prev, pager, next, jumper"
        class="pub-page"
        :current-page="searchInfo.page"
        :page-sizes="[20,50,100]"
        :page-size="searchInfo.size"
        :total="tableInfo.total"
        @current-change="search"
        @size-change="handleSizeChange"
      ></el-pagination>
    </AreaWarp>
  </div>
</template>
<script>
import { getTimestamp } from "../../../assets/js/time";
export default {
  data() {
    return {
      searchInfo: {
        realname: "",
        mobile: "",
        loanMoneyBegin: "", //打款金额开始
        loanMoneyEnd: "", //打款金额结束
        auditTime: "", //审核时间
        page: 1,
        size: 20
      },
      getLoaningListLoading: false,
      tableInfo: {
        list: [],
        size: 20,
        page: 1,
        total: 0
      },
      listSelection: [],
      exportShow:false
    };
  },
  methods: {
    //改变每页显示多少条
    handleSizeChange(val) {
      let that = this;
      that.searchInfo.size = val;
      that.searchInfo.page = 1;
      that.search();
    },
    //搜素数据
    search(currentPage) {
      let that = this;
      that.searchInfo.page = typeof currentPage == "number" ? currentPage : 1;
      let reqData = that.filter_parameter(that.searchInfo);
      if (!reqData) {
        return;
      }
      that.getLoaningListLoading = true;
      that.ajaxJson({
        url: "/finance/getLoanSuccessList",
        data: reqData,
        success: function(data) {
          if (data.code == "0") {
            that.tableInfo = data.data;
          }
          that.getLoaningListLoading = false;
        }
      });
    },
    //重置按钮
    reset() {
      let that = this;
      that.searchInfo = {
        realname: "",
        mobile: "",
        loanMoneyBegin: "", //打款金额开始
        loanMoneyEnd: "", //打款金额结束
        auditTime: "", //审核时间
        page: 1,
        size: 20
      };
      that.search();
    },
    //刷新
    Refresh() {
      let that = this;
      that.search();
    },
    //导出
    exportData() {
      let that = this;
      let reqData = that.filter_parameter(that.searchInfo);
      if (!reqData) {
        return;
      }
      let url =
        that.host +
        "/finance/exportLoanSuccessList?appId=" +
        that.$store.state.id;
      if (reqData.realname) {
        url += "&realname=" + reqData.realname;
      }
      if (reqData.mobile) {
        url += "&mobile=" + reqData.mobile;
      }
      if (reqData.loanMoneyBegin) {
        url += "&loanMoneyBegin=" + reqData.loanMoneyBegin;
      }
      if (reqData.loanMoneyEnd) {
        url += "&loanMoneyEnd=" + reqData.loanMoneyEnd;
      }
      if (reqData.auditTimeBegin) {
        url += "&auditTimeBegin=" + reqData.auditTimeBegin;
      }
      if (reqData.auditTimeEnd) {
        url += "&auditTimeEnd=" + reqData.auditTimeEnd;
      }
      console.log(url);
      window.open(url);
    },
    //是否显示导出
    isShowExport() {
      let that = this;
      let flag = that.urlPermissions().indexOf("/finance/exportLoanSuccessList");
      if (flag == "-1") {
        that.exportShow = false;
      } else {
        that.exportShow = true;
      }
    },
    //过滤条件
    filter_parameter(obj) {
      let that = this;
      let x = {};
      //姓名
      if (obj.realname) {
        x.realname = obj.realname;
      }
      //手机号
      if (obj.mobile) {
        if (!that.isMobile(obj.mobile)) {
          that.showMsg("请输入正确的手机号", "error");
          return;
        } else {
          x.mobile = obj.mobile;
        }
      }
      //审核时间
      if (obj.auditTime) {
        x.auditTimeBegin = obj.auditTime
          ? getTimestamp(obj.auditTime[0])
          : undefined;
        x.auditTimeEnd = obj.auditTime
          ? getTimestamp(obj.auditTime[1]) + 86399999
          : undefined;
      }
      //打款金额
      if (obj.loanMoneyBegin) {
        if (!/^[0-9]*$/.test(obj.loanMoneyBegin)) {
          that.showMsg("请输入正确的起始金额", "error");
          return;
        } else {
          x.loanMoneyBegin = obj.loanMoneyBegin;
        }
      }
      if (obj.loanMoneyEnd) {
        if (!/^[0-9]*$/.test(obj.loanMoneyEnd)) {
          that.showMsg("请输入正确的结束金额", "error");
          return;
        } else {
          x.loanMoneyEnd = obj.loanMoneyEnd;
        }
      }
      if (obj.loanMoneyBegin && obj.loanMoneyEnd) {
        if (Number(obj.loanMoneyBegin) >= Number(obj.loanMoneyEnd)) {
          that.showMsg("起始金额不得大于结束金额", "error");
          return;
        }
      }
      x.size = obj.size;
      x.page = obj.page;
      return x;
    }
  },
  created() {
    let that = this;
    Promise.all([that.isShowExport()]).then(arr=>{
      that.search()
    })
  }
};
</script>
<style lang="less">
.moneySuccess-page {
  .inputWidth {
    width: 120px;
  }
}
</style>
